package com.neuedu.dao.impl;

import com.neuedu.dao.FangChanDao;
import com.neuedu.model.FangChan;
import com.neuedu.model.XiaoQu;
import com.neuedu.utils.DBUtil;

import java.util.List;

public class FangChanDaoImpl implements FangChanDao {


    @Override
    public List<FangChan> selectPageList(Integer limitParams1, Integer limitParams2, String startTime, String endTime, String name) {
        List<FangChan> list = DBUtil.findByWhere(FangChan.class,
                "ruzhushijian >= ? and ruzhushijian <= ? and xiaoqumingcheng like ? limit ?,?",
                startTime, endTime, "%" + name + "%", limitParams1, limitParams2);
        return list;
    }

    @Override
    public int selectCount(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(FangChan.class,
                "ruzhushijian >= ? and ruzhushijian <= ? and xiaoqumingcheng like ?",
                startTime, endTime, "%" + name + "%").size();
    }

    @Override
    public int add(FangChan fangChan) {
        fangChan.setId(null);
        return DBUtil.insert(fangChan);
    }

    @Override
    public int del(Integer[] ids) {
        String where="id in (";
        for (int i = 0; i < ids.length; i++) {
            where=where+"?";
            if(i!=ids.length-1){
                where=where+",";
            }else{
                where=where+")";
            }
        }
        return DBUtil.delete(FangChan.class,where,ids);
    }

    @Override
    public FangChan selectFangChanOne(Integer id) {
        return DBUtil.findOneByWhere(FangChan.class, "id=?",id);
    }

    @Override
    public int updateFangChan(FangChan fangChan) {
        return DBUtil.updateSelective(FangChan.class,"id=?",fangChan.getId());
    }

    @Override
    public List<FangChan> selectAll() {
        return DBUtil.findAll(FangChan.class);
    }
}
